/*
 * @(#)AtnaContext.java
 * Date 2013-11-16
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.atna.client;

import java.lang.management.ManagementFactory;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.enterprise.context.ApplicationScoped;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-11-16
 * @author         Jim Horner
 */
@ApplicationScoped
public class AtnaContext {

    /** Field description */
    private final String hostName;

    /** Field description */
    private final String ipAddress;

    /** Field description */
    private final Logger logger = LoggerFactory.getLogger(getClass());

    /** Field description */
    private final String processId;

    /** Field description */
    private final String userName;

    /**
     * Constructs ...
     *
     */
    public AtnaContext() {

        super();

        this.userName = System.getProperty("user.name");
        this.processId = ManagementFactory.getRuntimeMXBean().getName();

        String ip = "UNKNOWN";
        String host = "UNKNOWN";

        try {

            host = InetAddress.getLocalHost().getCanonicalHostName();
            ip = InetAddress.getLocalHost().getHostAddress();

        } catch (UnknownHostException e) {

            logger.warn("Unable to get IP address and/or hostname.");
        }

        this.hostName = host;
        this.ipAddress = ip;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getHostName() {
        return hostName;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getIpAddress() {
        return ipAddress;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getProcessId() {
        return processId;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getUserName() {
        return userName;
    }
}
